Skip to content

fix(engine-core): dedupe additions to WeakMultimap @W-21387024#5738

Merged
wjhsf merged 3 commits intomasterfrom
wjh/weak-multi-map-patch
Mar 6, 2026
Merged

fix(engine-core): dedupe additions to WeakMultimap @W-21387024#5738
wjhsf merged 3 commits intomasterfrom
wjh/weak-multi-map-patch

Conversation

@wjhsf
Copy link
Contributor

@wjhsf wjhsf commented Mar 5, 2026

Skipping adding to the array for refs already present improves performance.

Because WeakRef is baseline widely available, I've also removed the fallback class definition.

Details

Does this pull request introduce a breaking change?

  • 😮‍💨 No, it does not introduce a breaking change.
  • 💔 Yes, it does introduce a breaking change.

Does this pull request introduce an observable change?

  • 🤞 No, it does not introduce an observable change.
  • 🔬 Yes, it does include an observable change.

GUS work item

@wjhsf wjhsf requested a review from a team as a code owner March 5, 2026 19:48
* It leaks in legacy browsers, which may be undesired.
*
* This implementation relies on the WeakRef/FinalizationRegistry proposal.
* For some background, see: https://github.com/tc39/proposal-weakrefs
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a stage 4, should be safe to point to mdn ?

// We could check for duplicate values here, but it doesn't seem worth it.
// We transform the output into a Set anyway
// Skip adding if already present
for (const weakRef of weakRefs) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we update the contract to: Set<WeakRef<V>>(), since it looks like that's what we want.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's kind of confusing because and the get method returns Set<V>, and we're comparing V but storing a group of WeakRef<V>. The values in the _map are purely internal, so it doesn't make a huge difference whether it's a set or an array.

According to this article, addition and iteration are comparable for sets and arrays, but sets have faster deletion. I made the switch.

Copy link
Contributor

@rax-it rax-it left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also think we should do CLCO cutoff before changing this, could be problematic 🤷🏼‍♂️

@wjhsf wjhsf merged commit 3b87d8c into master Mar 6, 2026
45 of 46 checks passed
@wjhsf wjhsf deleted the wjh/weak-multi-map-patch branch March 6, 2026 19:23
wjhsf added a commit that referenced this pull request Mar 6, 2026
* fix(engine-core): dedupe additions to `WeakMultimap`

Also remove legacy compat code

* chore: update link and fix case

* chore: remove legacy note
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants